<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="8">
          <el-form-item :label="$t('出资人类型')" prop="type">
            <el-select
              v-model="form.type"
              :disabled="form.id !== undefined"
              :placeholder="$t('出资人类型')"
              filterable
              @change="changeNameByTypeToSelect(form.type)"
            >
              <el-option
                v-for="dict in typeOptions"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col v-if="form.type === 'GR' || form.type === 'JG'" :span="8">
          <el-form-item :label="$t('出资人名称')" prop="investName" class="lp-class">
            <el-select v-model="form.investName" clearable :disabled="form.id !== undefined" filterable :placeholder="$t('出资人名称')" @change="lpDictsSelect">
              <el-option
                v-for="item in lpOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
            <el-button
              :disabled="form.id !== undefined"
              @click="addCustomer"
            >{{ $t('添加客户') }}
            </el-button>
          </el-form-item>
        </el-col>
        <el-col v-else :span="8">
          <el-form-item :label="$t('出资人名称')" prop="investName">
            <el-select v-model="form.investName" clearable :disabled="form.id !== undefined" filterable :placeholder="$t('出资人名称')" @change="lpDictsSelect">
              <el-option
                v-for="item in lpOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('合伙人类型')" prop="partnerType">
            <el-select v-model="form.partnerType" filterable :placeholder="$t('合伙人类型')">
              <el-option
                v-for="dict in partnerTypeOptions"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('合伙协议签订时间')" prop="investmentTime">
            <DatePicker
              v-model="form.investmentTime"
              :placeholder="$t('合伙协议签订时间')"
              @change="changeInvestmentTime"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('认缴时间')" prop="timeSubscription">
            <DatePicker
              v-model="form.timeSubscription"
              :placeholder="$t('认缴时间')"
            />

          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('认缴金额') + $t('金额单位')" prop="subscribedAmount">
            <Money
              v-model="form.subscribedAmount"
              unit="w"
              :placeholder="$t('认缴金额')"
              :disabled="!isEmpty(form.subscribedAmount) && !isEmpty(form.id) && !isWriteMoney"
              @change="calculationSubscriptionProportion(form.id, form.subscribedAmount)"
            >
              <template slot="append">
                <el-button v-if="!isEmpty(form.id)" @click="modifySubscription">{{ $t('修改认缴') }}</el-button>
              </template>
            </Money>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('认缴币种')" prop="subscribedCurrency">
            <dictSelect
              v-model="form.subscribedCurrency"
              size="small"
              :clearable="true"
              dictionary="currency"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('合同约定收益率(%)')" prop="contractualRateReturn">
            <Ratio v-model="form.contractualRateReturn" :placeholder="$t('合同约定收益率(%)')" />
          </el-form-item>
        </el-col>
        <!-- 无固定收益 -->
        <el-col :span="8">
          <el-form-item :label="$t('收益率构成')" prop="yieldStructure">
            <el-select v-model="form.yieldStructure" filterable :placeholder="$t('收益率构成')">
              <el-option
                v-for="dict in lpIncomeStructure"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('投资者性质')" prop="investorNature">
            <el-select v-model="form.investorNature" filterable :placeholder="$t('投资者性质')">
              <el-option
                v-for="dict in investorNatureOptions"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('投资者专业性')" prop="investorMajor">
            <el-select v-model="form.investorMajor" filterable :placeholder="$t('投资者专业性')">
              <el-option
                v-for="dict in investorMajorOptions"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('募资轮次')" prop="roundsId">
            <el-select v-model="form.roundsId" filterable :placeholder="$t('募资轮次')">
              <el-option
                v-for="dict in fundsOptions"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <!--        <el-col :span="8">-->
        <!--          <el-form-item :label="$t('预留管理费比例(%)')" prop="reservedManageFeeRatio">-->
        <!--            <Ratio v-model="form.reservedManageFeeRatio" :placeholder="$t('预留管理费比例(%)')" @change="calcReservedManageFee" />-->
        <!--          </el-form-item>-->
        <!--        </el-col>-->
        <el-col :span="8">
          <el-form-item :label="$t('付款银行户名称')" prop="bankName">
            <el-autocomplete
              v-model="form.bankName"
              popper-class="my-autocomplete"
              :fetch-suggestions="querySearch"
              :placeholder="$t('付款银行户名称')"
              show-word-limit
              :maxlength="200"
              @select="handleSelect"
            >
              <template slot-scope="{ item }">
                <div class="name">{{ item.bankName }}</div>
                <span class="addr">{{ item.bankAccount }}</span>
                <span class="addr">{{ item.bankAddress }}</span>
              </template>
            </el-autocomplete>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('付款银行户账号')" prop="bankAccount">
            <el-input v-model="form.bankAccount" :placeholder="$t('付款银行户账号')" show-word-limit :maxlength="200" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('开户行')" prop="bankAddress">
            <el-input v-model="form.bankAddress" :placeholder="$t('开户行')" show-word-limit :maxlength="200" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <!--<el-form-item :label="$t('联系人名称')" prop="investPersonCharge">-->
          <!--<el-input v-model="form.investPersonCharge" :placeholder="$t('联系人名称')" show-word-limit :maxlength="20" />-->
          <!--</el-form-item>-->
          <el-form-item :label="$t('联系人名称')" prop="investPersonCharge" show-word-limit :maxlength="20">
            <el-autocomplete
              v-model="form.investPersonCharge"
              popper-class="my-autocomplete"
              :fetch-suggestions="querySearchUser"
              :placeholder="$t('联系人名称')"
              show-word-limit
              :maxlength="200"
              @select="handleSelectUser"
            >
              <template slot-scope="{ item }">
                <div class="name">{{ item.contactsName }}</div>
                <span class="addr">{{ item.email }}</span>
                <span class="addr">{{ item.phone }}</span>
              </template>
            </el-autocomplete>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('联系人邮箱')" prop="investEmail">
            <span slot="label">
              {{ $t('联系人邮箱') }}
              <el-tooltip :content="$t('多个邮箱以英文分号隔开(;)')" placement="top">
                <i class="el-icon-question" />
              </el-tooltip>
            </span>
            <el-input v-model="form.investEmail" :placeholder="$t('联系人邮箱')" show-word-limit :maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('联系人手机号')" prop="investPhone">
            <el-input v-model="form.investPhone" :placeholder="$t('联系人手机号')" show-word-limit :maxlength="20" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('认缴比例(%)')" prop="subscriptionProportion">
            <Ratio v-model="form.subscriptionProportion" :placeholder="$t('认缴比例(%)')" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('累计实缴金额') + $t('金额单位')" prop="accumulatedPaidMount">
            <Money
              v-model="form.accumulatedPaidMount"
              unit="w"
              oninput="value=value.replace(/[^\d.]/g,'')"
              :placeholder="$t('累计实缴金额')"
              disabled
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item v-show="isRate" :label="$t('累计实缴金额') + $t('RMB') + $t('金额单位')" prop="accumulatedPaidMount">
            <Money
              v-model="form.accumulatedPaidMountRmb"
              unit="w"
              oninput="value=value.replace(/[^\d.]/g,'')"
              :placeholder="$t('累计实缴金额') + $t('RMB') "
              disabled
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('最新IRR')" prop="latestIrr">
            <el-input v-model="form.latestIrr" :placeholder="$t('最新IRR')" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('预留管理费')" prop="reservedManageFee">
            <Money v-model="form.reservedManageFee" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('特殊要求')" prop="specialRequirements">
            <el-input v-model="form.specialRequirements" type="textarea" maxlength="2000" :placeholder="$t('特殊要求')" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')">
            <el-input v-model="form.remark" type="textarea" maxlength="2000" :placeholder="$t('备注')" />
          </el-form-item>
        </el-col>
      </el-row>
      <div style="margin-top: 15px">
        <!--缴款明细-->
        <div class="area-header">
          <span class="area-header-title">{{ $t('缴款明细') }}</span>
        </div>
        <el-table :data="form.fundLpPaymentList" border class="nowrapTable formTable">
          <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column v-if="fundDataType === 'fund'" :label="$t('Call款期次')" align="center" min-width="160">
            <template slot="header" slot-scope="{}">
              <span>{{ $t('Call款期次') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'fundLpPaymentList.' + scope.$index + '.callPeriod'"
                :rules="fundLpPaymentListRules.callPeriod"
              >
                <el-select v-model="scope.row.callPeriod" filterable clearable :placeholder="$t('Call款期次')">
                  <el-option
                    v-for="dict in callPeriodOptions"
                    :key="dict.dictValue"
                    :label="$t(dict.dictLabel)"
                    :value="dict.dictValue"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('缴款时间')" align="center" min-width="150">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('缴款时间') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'fundLpPaymentList.' + scope.$index + '.payDate'"
                :rules="fundLpPaymentListRules.payDate"
              >
                <DatePicker v-model="scope.row.payDate" :placeholder="$t('缴款时间')" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('缴款金额') + $t('金额单位')" align="center" min-width="160">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('缴款金额') }}{{ $t('金额单位') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'fundLpPaymentList.' + scope.$index + '.payMoney'"
                :rules="fundLpPaymentListRules.payMoney"
              >
                <Money v-model="scope.row.payMoney" unit="w" :placeholder="$t('发生金额') +$t('金额单位')" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="isRate && false" :label="$t('汇率')" align="center">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('汇率') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'fundLpPaymentList.' + scope.$index + '.exchangeRate'"
                :rules="fundLpPaymentListRules.exchangeRate"
              >
                <ExchangeRate v-model="scope.row.exchangeRate" :currency="fundCurr" :date="scope.row.payDate" :placeholder="$t('汇率')" />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="isRate && false" :label="$t('缴款金额')+ $t('RMB') + $t('金额单位')" align="center">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('缴款金额')+ $t('RMB') + $t('金额单位') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'fundLpPaymentList.' + scope.$index + '.payMoneyRmb'"
                :rules="fundLpPaymentListRules.payMoneyRmb"
              >
                <ExchangeRateMoney
                  v-model="scope.row.payMoneyRmb"
                  :rate="scope.row.exchangeRate"
                  :money="scope.row.payMoney"
                  :placeholder="$t('发生金额') + $t('RMB') + $t('金额单位')"
                  unit="w"
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column v-if="!otherBtnHide" :label="$t('操作')" align="center" min-width="60px">
            <template slot-scope="scope">
              <el-button
                type="text"
                icon="el-icon-delete"
                @click="delFundLpPaymentHandle(scope.$index, scope.row)"
              />
            </template>
          </el-table-column>
        </el-table>
        <div v-if="!otherBtnHide" class="tol">
          <el-button v-hasPermi="['fund:investor:edit']" type="primary" icon="el-icon-plus" size="mini" @click="addFundLpPaymentList">{{
            $t('添加')
          }}
          </el-button>
        </div>
      </div>

      <div style="margin-top: 15px">
        <!--缴款明细-->
        <div class="area-header">
          <span class="area-header-title">{{ $t('LPA条款') }}</span>
        </div>
        <el-table :data="form.fundInvestorTermsList" border class="nowrapTable formTable">
          <el-table-column :label="$t('序号')" align="center" width="50">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('条款类型')" align="center" width="300">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('条款类型') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'fundInvestorTermsList.' + scope.$index + '.clauseType'"
                :rules="fundInvestorTermsListRules.clauseType"
              >
                <dictSelect
                  v-model="scope.row.clauseType"
                  :clearable="true"
                  dictionary="lpa_type"
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('条款内容')" align="center" min-width="220">
            <template slot="header" slot-scope="{}">
              <i style="color: #ff4949;margin-right: 4px;">*</i>
              <span>{{ $t('条款内容') }}</span>
            </template>
            <template slot-scope="scope">
              <el-form-item
                :prop="'fundInvestorTermsList.' + scope.$index + '.clauseContent'"
                :rules="fundInvestorTermsListRules.clauseContent"
              >
                <el-input
                  v-model="scope.row.clauseContent"
                  type="textarea"
                  :autosize="{ minRows: 1, maxRows: 8}"
                  maxlength="2000"
                />
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column :label="$t('提醒配置')" align="center" width="100">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" plain @click="remindHandle(scope.$index)">{{ $t('配置') }}</el-button>
            </template>
          </el-table-column>
          <el-table-column v-if="!otherBtnHide" :label="$t('操作')" align="center" width="60px">
            <template slot-scope="scope">
              <el-button
                type="text"
                icon="el-icon-delete"
                @click="delHandleTerms(scope.$index, scope.row)"
              />
            </template>
          </el-table-column>
        </el-table>
        <div v-if="!otherBtnHide" class="tol">
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="addFundInvestorTerms">{{ $t("添加") }}</el-button>
        </div>
      </div>
      <FileTable has-permi="fund:investor" :list.sync="form.fileList" data-type="fund_investor" :business-id="this.$route.query.id === undefined ? currentFundId : this.$route.query.id" :btn-show="!otherBtnHide" />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存，保存并启动流程，取消 三个按钮-->
      <SaveBtn has-permi="fund:investor" :cancel-show="!otherBtnHide" :save-show="!otherBtnHide" />
    </div>

    <!-- 添加或修改客户管理对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="formOpen"
      :close-on-click-modal="false"
      :lock-scroll="false"
      custom-class="dialogForm"
      width="70%"
      append-to-body
    >
      <lpBaseForm ref="lpBaseForm" @senddata="sendData" />
    </el-dialog>
    <!-- 定时提醒 -->
    <el-dialog
      :title="$t('定时提醒')"
      :visible.sync="remindOpen"
      width="40%"
      :destroy-on-close="true"
      :close-on-click-modal="false"
      :lock-scroll="false"
      append-to-body
    >
      <el-form
        v-if="form.fundInvestorTermsList[termsIndex]"
        ref="remindForm"
        :model="form.fundInvestorTermsList[termsIndex]"
        :rules="remindRules"
        label-width="120px"
        label-position="top"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('提醒频率')" prop="reminderFrequency">
              <el-radio-group v-model="form.fundInvestorTermsList[termsIndex].reminderFrequency">
                <el-radio
                  v-for="dict in reminderFrequencyOptions"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                >{{ $t(dict.dictLabel) }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col v-if="form.fundInvestorTermsList[termsIndex].reminderFrequency === 'TIMER'" :span="12">
            <el-form-item :label="$t('定时提醒时间')" prop="remindTime">
              <el-date-picker
                v-model="form.fundInvestorTermsList[termsIndex].remindTime"
                clearable
                style="width: 200px"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm"
                :placeholder="$t('定时提醒时间')"
              />
            </el-form-item>
          </el-col>
          <el-col v-else :span="24">
            <el-form-item :label="$t('频率提醒表达式')" prop="cron">
              <Cron v-model="form.fundInvestorTermsList[termsIndex].cron" :cron-value.sync="form.fundInvestorTermsList[termsIndex].frequencyCronValue" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('提醒状态')" prop="status">
              <el-switch
                v-model="form.fundInvestorTermsList[termsIndex].status"
                active-color="#13ce66"
                inactive-color="#ff4949"
                :active-text="$t('开启')"
                :inactive-text="$t('关闭')"
                :active-value="'1'"
                :inactive-value="'0'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('提醒人')" prop="remindUserId">
              <UserSelect
                v-model="form.fundInvestorTermsList[termsIndex].remindUserId"
                :multiple="true"
                :placeholder="$t('提醒人')"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="remindConfirmHandle">{{ $t('确定') }}</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :title="$t('变更出资人认缴')"
      :visible.sync="changeInvestSubscription"
      width="30%"
      :destroy-on-close="true"
      :close-on-click-modal="false"
      :lock-scroll="false"
      custom-class="dialogCustomClass"
      append-to-body
    >
      <template>
        <div v-loading="changeInvestSubscriptionLoading">
          <el-form
            ref="moneyForm"
            :model="moneyForm"
            :rules="moneyRules"
            label-width="120px"
            class="dataForm"
          >
            <el-row>
              <el-col :span="24">
                <el-form-item :label="$t('变更时间')" prop="timeSubscription">
                  <el-date-picker
                    v-model="moneyForm.timeSubscription"
                    type="date"
                    :placeholder="$t('变更时间')"
                    :picker-options="pickerOptions"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item :label="$t('认缴金额') + $t('金额单位')" prop="subscribedAmount">
                  <Money
                    v-model="moneyForm.subscribedAmount"
                    unit="w"
                    :placeholder="$t('认缴金额')"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item :label="$t('是否保存份额变更记录')" prop="changeInShare">
                  <span slot="label" style="margin-left: 50px;">
                    {{ $t('是否保存份额变更记录') }}
                  </span>
                  <div style="position: absolute;top: -38px;">
                    <el-switch
                      v-model="moneyForm.changeInShare"
                      active-color="#13ce66"
                      inactive-color="#dbdbdb"
                      active-value="Y"
                      inactive-value="N"
                    />
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div slot="footer" class="dialog-footer custom-save-btn-investor-form">
            <el-button @click="changeInvestSubscription = false">{{ $t('取消') }}</el-button>
            <el-button has-permi="fund:investor" type="primary" @click="saveSubscription">{{ $t('保存') }}</el-button>
          </div>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import {
  saveFundInvestor,
  getFundInvestor,
  calculationAmount,
  checkInvestor,
  changeNameByType,
  updateSubscription
} from '@/api/fund/investor/fundInvestor'
import lpBaseForm from '@/views/fund/lpBase/lpBaseForm.vue'
import {
  getFundCallQCByFundId,
  sumContributionsGroupCallPeriod
} from '@/api/fund/callmoney/fundCallMoney'
import { delFundLpPayment, delFundInvestorLpa } from '@/api/fund/lpPayment/fundLpPayment'
import { getFundBase } from '@/api/fund/fundBase'
import { getSystemCurrency } from '@/api/system/config'
import { ruoyiFloat } from '@/utils/ruoyi'
import { getLpBase, saveLpBase } from '@/api/fund/lpBase/lpBase'
import { findRounds } from '@/api/fund/rounds/fundRounds'
import { findLpBaseBankAccountByLpId } from '@/api/fund/lpBase/lpBase.js'
import { fundDataType } from '@/api/fund/fundBase'
  import Cron from '@/components/Cron'
import { listFundInvestorLpaNotPer } from '@/api/fund/investorLpa/fundInvestorLpa'
import { getContactsByBusinessId } from '@/api/deal/contact/contactsPerson'
export default {
  components: {
    lpBaseForm,
    Cron
  },
  props: {
    otherBtnHide: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      // 表单参数
      form: {
        fileList: [],
        fundLpPaymentList: [],
        fundInvestorTermsList: []
      },
      // 页面加载后的初始化数据. 不包括用户修改后的
      initForm: undefined,
      // 遮罩层
      formOpen: false,
      fundCurr: '',
      defCurr: '',
      isRate: false,
      // otherBtnHide: false,
      // 遮罩层
      loading: false,
      // 表单校验
      rules: {
        type: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        name: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        customerId: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        partnerType: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        currency: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        investName: [{ required: true, validator: this.checkInvestor, trigger: 'blur' }],
        investmentTime: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        incomeDistributionMethod: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        // timeSubscription: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        subscribedAmount: [{ required: true, validator: this.checkEquityZero, trigger: ['blur'] }],
        reservedManageFeeRatio: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
        investEmail: [{ required: false, validator: this.checkInvestEmail, trigger: 'blur' }]
        // investPhone: [{ required: false, validator: checkPhone, trigger: 'blur' }],
        // investEmail: [{ required: false, type: 'email', message: this.$t('邮箱格式不正确') }]
      },
      // 缴款明细表单校验
      fundLpPaymentListRules: {
        investorName: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        workEnterprise: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        position: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        term: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        payMoney: [{ required: true, validator: this.moneyCheckPeriodMoney, trigger: ['blur'] }],
        payDate: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
      },
      fundInvestorTermsListRules: {
           clauseType: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
            clauseContent: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
      },
       remindRules: {
                  timerReminderTime: { required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] },
                  cron: { required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] },
                  reminderFrequency: { required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] },
                  remindTime: { required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] },
                  remindUserId: { required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }
       },
      // 客户类型字典
      typeOptions: [],
      lpIncomeStructure: [],
      callPeriodOptions: [],
      // 合伙人类型
      partnerTypeOptions: [],
      // 客户下拉
      lpOptions: [],
      // 是否隐藏保存等按钮
      btnHide: false,
      // 隐藏客户管理添加按钮
      hiddenButtonAddC: '',
      title: undefined,
      // 当前出资人是否存在
      whereIsCheckInvestor: false,
      // 募资轮次下拉菜单
      fundsOptions: [],
      // 投资者性质字典
      investorNatureOptions: [],
      // 投资者专业性字典
      investorMajorOptions: [],
      restaurants: [],
      restaurantsUser: [],
      // 获取基金数据类型，如果是spv则不展示缴款
      fundDataType: 'fund',
      // 基金外部调用该页面使用
      currentFundId: undefined,
      termsIndex: undefined,
      remindOpen: false,
      reminderFrequencyOptions: [],
      // 修改认缴弹窗
      changeInvestSubscription: false,
      changeInvestSubscriptionLoading: false,
      isWriteTimeSubscription: false,
      isWriteMoney: false,
      moneyForm: {
        subscribedAmount: undefined,
        timeSubscription: undefined,
        changeInShare: 'Y'
      },
      moneyRules: {
        timeSubscription: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        subscribedAmount: [{ required: true, validator: this.checkEquityZero, trigger: ['blur'] }],
        changeInShare: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }]
      }
    }
  },
  computed: {
    pickerOptions() {
      var _this = this
      return {
        disabledDate(time) {
          if (time && !_this.isEmpty(_this.initForm.timeSubscription)) {
            return time.getTime() < new Date(_this.initForm.timeSubscription)
          }
          return false
        }
      }
    }
  },
  created() {
     this.getDicts('reminder_frequency').then(response => {
              this.reminderFrequencyOptions = response.data
            })
    // 出资人类型字典
    this.getDicts('fund_investor_type').then(response => {
      response.data.forEach(item => {
        this.typeOptions.push(item)
      })
    })
    // 收益率构成
    this.getDicts('lp_Income_structure').then(response => {
      this.lpIncomeStructure = response.data
    })
    // 合伙人类型
    this.getDicts('partner_type').then(response => {
      this.partnerTypeOptions = response.data
    })
    // 投资者性质
    this.getDicts('investor_nature').then(response => {
      this.investorNatureOptions = response.data
    })
    // 投资者专业性
    this.getDicts('investor_major').then(response => {
      this.investorMajorOptions = response.data
    })
    var fundId = this.$route.query.id === undefined ? this.form.fundId : this.$route.query.id
    if (fundId) {
      this.initData(fundId)
    }
    findRounds(this.$route.query.id).then(response => {
      this.fundsOptions = response.data
    })
    this.getFundDataType(this.$route.query.id)
    this.$bus.$emit('async_done')
  },
  methods: {
    // 初始化数据
    async init(data) {
      console.log('全文检索data', data)
      this.loading = true
      this.reset()
      this.initCurr()
      if (data != null && data.id !== undefined) {
        // 获取基金币种
        this.hiddenButtonAddC = 'hidden'
        getFundInvestor(data.id).then(response => {
          this.form = response.data
          if (this.form) {
            this.initForm = JSON.parse(JSON.stringify(response.data))
          }
          this.isWriteTimeSubscription = this.isEmpty(this.form.timeSubscription)
          this.isWriteMoney = this.isEmpty(this.form.subscribedAmount)
           this.form.fundInvestorTermsList.forEach(e => {
              e.status = parseInt(e.status)
           })
          // 加载认缴比例
          this.calculationSubscriptionProportion(this.form.id, this.form.subscribedAmount)
          this.initData(this.form.fundId)
          // 加载名称
          this.form.investName = data.userName
          if ((this.form.investName === null || this.form.investName === undefined || this.form.investName === '') && this.form.customerId) {
            if (this.form.type) {
              changeNameByType(this.form.type).then(response => {
                this.lpOptions = response.data || []
                var row = this.lpOptions.find(v => v.id === this.form.customerId)
                if (row) {
                  this.form.investName = row.name
                }
              })
            }
          }
          this.loading = false
          this.loadAll(response.data.customerId)
        })
      } else {
        this.reset()
        this.loading = false
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        fundId: this.$route.query.id === undefined ? this.currentFundId : this.$route.query.id,
        type: undefined,
        name: undefined,
        investName: undefined,
        investmentTime: undefined,
        incomeDistributionMethod: undefined,
        timeSubscription: undefined,
        subscribedAmount: undefined,
        contractualRateReturn: undefined,
        yieldStructure: undefined,
        currency: undefined,
        subscribedCurrency: 'CNY',
        reservedManageFeeRatio: 0,
        reservedManageFee: undefined,
        partnerType: 'LP',
        subscriptionProportion: undefined,
        accumulatedPaidMount: undefined,
        accumulatedPaidMountRmb: undefined,
        bankName: undefined,
        investPhone: undefined,
        investEmail: undefined,
        investPersonCharge: undefined,
        bankAccount: undefined,
        bankAddress: undefined,
        fileList: [],
        fundLpPaymentList: [],
        specialRequirements: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        roundsId: undefined,
        investorNature: undefined,
        investorMajor: undefined,
        fundInvestorTermsList: []
      }
      this.resetForm('form')
    },
    // 添加本人及关系密切家庭成员一级市场对外投资情况对象
    addFundLpPaymentList() {
      const row = {
        id: undefined,
        fundId: '',
        investId: '',
        payDate: '',
        payMoney: '',
        callPeriod: '',
        remark: ''
      }
      if (!(this.form.fundLpPaymentList instanceof Array)) {
        this.$set(this.form, 'fundLpPaymentList', [])
      }
      this.$nextTick(() => {
        this.form.fundLpPaymentList.push(row)
      })
    },
    // 删除本人及关系密切家庭成员一级市场对外投资情况对象
    delFundLpPaymentHandle(index, row) {
      // eslint-disable-next-line no-undef
      const id = row.id
      if (id !== undefined && id !== '' && id != null) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        })
            .then(function() {
              return delFundLpPayment(id)
            }).then(() => {
          this.form.fundLpPaymentList.splice(index, 1)
          return this.msgSuccess(this.$t('删除成功'))
        })
            .catch(function() {
            })
      } else {
        this.form.fundLpPaymentList.splice(index, 1)
      }
    },
    // 取消按钮
    cancel() {
      this.reset()
      this.hiddenButtonAddC = ''
      this.$parent.$parent.investFormOpen = false
      if (this.$parent.$parent.reset !== undefined) {
        this.$parent.$parent.reset()
      }
    },
    // 初始化数据
    initData(fundId) {
      this.loading = true
      getFundCallQCByFundId(fundId).then(response => {
        this.callPeriodOptions = response.data
        this.loading = false
      })
    },
    // 关闭form页面
    closeForm() {
      this.reset()
      this.hiddenButtonAddC = ''
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      this.$parent.$parent.investFormOpen = false
      // 刷新list页面
      if (this.$parent.$parent.getList !== undefined) {
        this.$parent.$parent.getList()
      }
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.whereIsCheckInvestor) {
            // 询问是否完善出资人信息
            var that = this
            that.$confirm(that.$t('是否完善出资人信息?'), that.$t('提示'), {
              confirmButtonText: that.$t('完善'),
              cancelButtonText: that.$t('跳过'),
              type: 'warning'
            })
            .then(function() {
              // 完善
              that.formOpen = true
              that.$nextTick(() => {
                that.$refs.lpBaseForm.init(null)
                // 全称
                that.$refs.lpBaseForm.form.name = that.form.investName
                // 简称
                that.$refs.lpBaseForm.form.shortName = that.form.investName
                // 关注等级
                that.$refs.lpBaseForm.form.followLevel = 'ybgz'
                // 业务经理
                that.$refs.lpBaseForm.form.manager = [that.$store.state.user.userId]
                // 客户类型
                that.$refs.lpBaseForm.form.type = that.form.type
              })
            })
            .catch(function() {
              that.loading = true
              const data = {
                type: that.form.type,
                name: that.form.investName,
                shortName: that.form.investName,
                followLevel: 'ybgz',
                manager: [that.$store.state.user.userId]
              }
              saveLpBase(data).then(response => {
                if (response.code === 200) {
                  that.form.customerId = response.data.id
                  that.saveSubmitForm()
                } else {
                  that.msgError(that.$t('发生异常!'))
                  that.loading = false
                }
              })
            })
          } else {
            this.saveSubmitForm()
          }
        } else {
          this.locationError(document)
        }
      })
    },
    // 保存表单
    saveSubmitForm() {
      console.log(this.form)
      this.loading = true
      saveFundInvestor(this.form).then(response => {
        if (response.code === 200) {
          this.$emit('sendInvestData', this.form)
          this.msgSuccess(this.$t('保存成功'))
          this.closeForm()
        } else {
          this.msgError(response.msg)
        }
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    /** 项目收款数据回显处理 */
    changeInvest(data) {
      this.$nextTick(() => {
        this.loading = true
        this.$set(this.form, 'name', undefined)
        this.$set(this.form, 'investName', undefined)
        if (data != null && data.id !== undefined) {
          this.$set(this.form, 'type', data.investorType)
          this.$set(this.form, 'customerId', data.investorId)
          this.$set(this.form, 'fundId', data.fundId)
          this.$set(this.form, 'investName', data.investorName)
          this.$set(this.form, 'subscribedAmount', data.finalAmount)
          this.$set(this.form, 'timeSubscription', data.finalDate)
          this.$set(this.form, 'investmentTime', data.finalDate)
          this.loading = false
        } else {
          this.loading = false
        }
      })
    },
    // 根据类型 改变名称下拉
    changeNameByTypeToSelect: function(type) {
      console.log('加载出资人名称')
      // this.form.customerId = ''
      this.form.investName = undefined
      if (type !== null && type !== undefined && type !== '') {
        changeNameByType(type).then(response => {
          this.lpOptions = response.data
        })
      }
    },
    // 修改页面. 点击修改认缴按钮
    modifySubscription() {
      if (this.isWriteTimeSubscription || this.isWriteMoney) {
        this.$confirm(this.$t('请先填写认缴时间和认缴金额且保存后再进行此操作!'), this.$t('提示'), {
          confirmButtonText: '好的',
          cancelButtonText: '关闭',
          type: 'warning'
        }).then(() => {
        }).catch(() => {
        })
      } else {
        // 打开弹窗
        this.changeInvestSubscription = true
        this.$nextTick(() => {
          this.moneyForm.timeSubscription = this.form.timeSubscription
          this.moneyForm.subscribedAmount = this.form.subscribedAmount
        })
      }
    },
    // 保存认缴
    saveSubscription() {
      this.$refs['moneyForm'].validate(valid => {
        if (valid) {
          this.changeInvestSubscriptionLoading = true
          const data = {
            id: this.form.id,
            timeSubscription: this.moneyForm.timeSubscription,
            subscribedAmount: this.moneyForm.subscribedAmount,
            changeInShare: this.moneyForm.changeInShare
          }
          updateSubscription(data).then(response => {
            if (response.msg === 'success') {
              this.msgSuccess(this.$t('操作成功'))
              this.changeInvestSubscription = false
              this.form.subscribedAmount = this.moneyForm.subscribedAmount
              this.initForm.subscribedAmount = this.moneyForm.subscribedAmount
            } else {
              this.msgWarning(this.$t(response.msg))
            }
            this.changeInvestSubscriptionLoading = false
            this.changeInvestSubscription = false
          }).catch(() => {
            this.changeInvestSubscriptionLoading = false
          })
        } else {
          this.locationError(document)
        }
      })
    },
    // 根据当前认缴金额算出认缴比例
    calculationSubscriptionProportion: function(id, money) {
      if (money < this.form.accumulatedPaidMount) {
        this.msgError('认缴金额不能小于累计实缴金额')
        this.form.subscribedAmount = this.form.accumulatedPaidMount
      } else {
        calculationAmount(id, this.form.fundId, money).then(response => {
          this.form.subscriptionProportion = response.data
        })
      }
      // 计算预留管理费
      this.calcReservedManageFee()
    },
    // 根据当前认缴金额和预留管理费比例计算预留管理费
    calcReservedManageFee: function() {
      if (this.form.subscribedAmount !== undefined && this.form.subscribedAmount !== '' &&
        this.form.reservedManageFeeRatio !== undefined && this.form.reservedManageFeeRatio !== '') {
        this.form.reservedManageFee = this.form.subscribedAmount * this.form.reservedManageFeeRatio / 100
      }
    },
    lpDictsSelect(id) {
      this.loadAll(id)
      this.form.customerId = id
      if (this.lpOptions.length > 0) {
        this.lpOptions.forEach(item => {
          if (item.id === id) {
            this.form.investName = item.name
            if (item.type === 'GR' || item.type === 'JG') {
              getLpBase(id).then(response => {
                console.log(response)
                if (response.data) {
                  if (response.data.email) {
                    this.form.investEmail = response.data.email
                  }
                }
              })
            }
          }
        })
      }
    },
    // 合伙协议签订时间变化时判断是否同步填写认缴时间
    changeInvestmentTime() {
      if (!this.isEmpty(this.form.investmentTime)) {
        this.form.timeSubscription = this.form.investmentTime
      }
    },
    // 添加新到的客户
    addCustomer() {
      this.formOpen = true
      this.title = this.$t('添加客户')
      this.$nextTick(() => {
        this.$refs.lpBaseForm.init({ type: this.form.type })
      })
    },
    // 接受子页面传递值
    getList() {
      this.loading = false
    },

    sendData: function(data) {
      this.lpOptions.push({ id: data.id, name: data.name, create_by: data.createBy.id, type: data.type })
      this.$nextTick(() => {
        this.form.name = data.name
        this.form.type = data.type
        this.form.customerId = data.id
        this.form.investName = data.name
      })
    },
    // 初始化币种信息
    async initCurr() {
      await getFundBase(this.$route.query.id === undefined ? this.currentFundId : this.$route.query.id).then(res => {
        this.fundCurr = res.data.currency
      })
      await getSystemCurrency().then(res => {
        if (res.code === 200) {
          this.defCurr = res.data
        } else {
          this.msgError(res.msg)
        }
      })
      this.isRate = this.defCurr !== this.fundCurr
    },
    // 校验出资人是否存在
    async checkInvestor(rule, value, callback) {
      var that = this
      that.whereIsCheckInvestor = false
      if (that.form.investName === undefined || that.form.investName === '') {
        callback(new Error(that.$t('必填信息')))
      }
      if (that.form.id === undefined || that.form.id === null || that.form.id === '') {
        var type = that.form.type
        var checkRes = await checkInvestor(type, that.form.investName)
        console.log(checkRes)
        if (checkRes.data.length < 1 && (type === 'JG' || type === 'GR')) {
          that.whereIsCheckInvestor = true
          callback(new Error(that.$t('当前出资人不存在,仅个人和机构可手动录入!')))
        } else {
          that.form.customerId = checkRes.data[0].id
          callback()
        }
      } else {
        callback()
      }
    },
    checkInvestEmail(rule, value, callback) {
      if (!this.isEmpty(value)) {
        const email = value.split(';')
        var reg = /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+\.[a-zA-Z]{2,5})$/
        if (!reg.test(email[0])) {
          callback(new Error(this.$t('请输入有效的邮箱')))
        } else {
          if (email.length > 1) {
            var flag = true
            email.forEach((v) => {
              console.log(v)
              if (!reg.test(v) && flag) {
                flag = false
                callback(new Error(this.$t('请输入有效的邮箱')))
              }
            })
            if (flag) {
              callback()
            }
          } else {
            callback()
          }
        }
      } else {
        callback()
      }
    },
    /**
     * 金额要大于等于0
     */
    checkEquityZero(rule, value, callback) {
      console.log(value)
      if (!this.isEmpty(value)) {
        if (value >= 0) {
          callback()
        } else {
          callback(new Error(this.$t('认缴金额不能小于0')))
        }
      } else {
        callback(new Error(this.$t('必填信息')))
      }
    },
    /**
     * 校验缴款明细的剩余缴款金额
     */
    moneyCheckPeriodMoney(rule, value, callback) {
      if (this.isEmpty(value)) {
        callback(new Error(this.$t('必填信息')))
      } else {
        // 获取当前选中的Call款期次
        const rowIndex = parseInt(rule.field.substring(rule.field.indexOf('.') + 1, rule.field.lastIndexOf('.')))
        const callPeriod = this.form.fundLpPaymentList[rowIndex].callPeriod
        // 选择了期次情况
        if (!this.isEmpty(callPeriod)) {
          // 获取当前列表中的当前期次的金额总和
          var moneySum = 0
          this.form.fundLpPaymentList && this.form.fundLpPaymentList.forEach(item => {
            if (item.callPeriod === callPeriod) {
              moneySum += ruoyiFloat().formatNum(item.payMoney)
            }
          })
          // 获取总额后, 根据期次ID和出资人ID, 去查询他是否超过该其次中的认缴金额的总和
          const data = {
            fundId: this.$route.query.id === undefined ? this.form.fundId : this.$route.query.id,
            investId: this.form.customerId,
            callPeriod: callPeriod
          }
          sumContributionsGroupCallPeriod(data).then(response => {
            if (moneySum > response.data) {
              callback(this.$t('当前列表总额不能超过该期次Call款剩余金额'))
            } else if (moneySum > ruoyiFloat().formatNum(this.form.subscribedAmount)) {
              callback(this.$t('不能超过认缴金额'))
            } else {
              callback()
            }
          })
        } else {
          var moneySum2 = 0
          this.form.fundLpPaymentList && this.form.fundLpPaymentList.forEach((item, index) => {
            if (index !== rowIndex) {
              moneySum2 += ruoyiFloat().formatNum(item.payMoney)
            }
          })
          // 如果出资人认缴金额-call款所有金额(本子表内, 并且不包含自己) > 当前录入的金额则提示错误
          if (ruoyiFloat().formatNum(this.form.fundLpPaymentList[rowIndex].payMoney) > (ruoyiFloat().formatNum(this.form.subscribedAmount) - moneySum2)) {
            callback(this.$t('当前列表汇总额后会超过剩余认缴金额'))
          } else {
            callback()
          }
        }
      }
    },
    handleSelect(item) {
      this.form.bankName = item.bankName
      this.form.bankAccount = item.bankAccount
      this.form.bankAddress = item.bankAddress
    },
    handleSelectUser(item) {
      this.form.investPersonCharge = item.contactsName
      this.form.investEmail = item.email
      this.form.investPhone = item.phone
    },
    querySearch(queryString, cb) {
      console.log(queryString)
      cb(this.restaurants)
      // var restaurants = this.restaurants
      // var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants
      // // 调用 callback 返回建议列表的数据
      // cb(results)
    },
    // createFilter(queryString) {
      // return (restaurant) => {
      //   return (restaurant.bankName.toLowerCase().includes(queryString.toLowerCase()))
      // }
    // },
    querySearchUser(queryString, cb) {
      console.log(queryString)
      cb(this.restaurantsUser)
    },
    loadAll(id) {
      this.restaurants = []
      this.restaurantsUser = []
      if (this.isEmpty(this.form.id)) {
        this.handleSelect({ bankName: '', bankAccount: '', bankAddress: '' })
        this.handleSelectUser({ contactsName: '', email: '', phone: '' })
      }
      if (this.form.type === 'GR' || this.form.type === 'JG') {
        // 银行信息
        findLpBaseBankAccountByLpId(id).then(response => {
          console.log(response.data)
          if (response.data !== null && response.data.length > 0) {
            response.data.forEach(item => {
              this.restaurants.push(item)
            })
            if (!this.isEmpty(this.restaurants) && this.isEmpty(this.form.bankName) && this.isEmpty(this.form.id)) {
              this.handleSelect(this.restaurants[0])
            }
          }
        })
        // 用户信息
        getContactsByBusinessId(id).then(res => {
          if (res.data !== null && res.data.length > 0) {
            res.data.forEach(item => {
              this.restaurantsUser.push(item)
            })
            if (!this.isEmpty(this.restaurantsUser) && this.isEmpty(this.form.investPersonCharge) && this.isEmpty(this.form.id)) {
              this.handleSelectUser(this.restaurantsUser[0])
            }
          }
        })
        // 根据客户ID和基金ID查询出已经录入的客户的LPA关键条款数据
        const data = {
          fundId: this.$route.query.id,
          lpId: id
        }
        listFundInvestorLpaNotPer(data).then(response => {
          console.log('LPA条款列表', response.rows)
          this.form.fundInvestorTermsList = response.rows
        })
      }
    },
    // 获取基金数据类型，如果是spv则不展示缴款
    getFundDataType(fundId) {
      fundDataType(fundId).then(res => {
        this.fundDataType = res.data
      })
    },
      remindHandle(index) {
            console.log(this.form.fundInvestorTermsList[index])
            this.termsIndex = index
            this.remindOpen = true
      },
      addFundInvestorTerms() {
         const row = {
              id: undefined,
              clauseType: undefined,
              clauseContent: undefined,
              reminderFrequency: 'TIMER',
              remindTime: undefined,
              cron: undefined,
              status: '1',
              remindUserId: undefined
            }
            if (!(this.form.fundInvestorTermsList instanceof Array)) {
              this.$set(this.form, 'fundInvestorTermsList', [])
            }
            this.$nextTick(() => {
              this.form.fundInvestorTermsList.push(row)
            })
      },
      delHandleTerms(index, row) {
           var that = this
            const id = row.id
            if (id !== undefined && id !== '' && id != null) {
              this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
                confirmButtonText: this.$t('确定'),
                cancelButtonText: this.$t('取消'),
                type: 'warning'
              })
              .then(function() {
                delFundInvestorLpa(id).then(response => {
                  if (response.code === 200) {
                    that.form.fundInvestorTermsList.splice(index, 1)
                    that.msgSuccess(that.$t('删除成功!'))
                  } else {
                    that.msgSuccess(that.$t('删除失败!'))
                  }
                })
              }).catch(function() {})
            } else {
              this.form.fundInvestorTermsList.splice(index, 1)
            }
      },
      remindConfirmHandle() {
            this.$refs['remindForm'].validate(valid => {
              if (valid) {
                this.remindOpen = false
              }
            })
          }
  }
}
</script>
<style lang="scss" scoped>
.readonlyCustom {
  background-color: #e3e3e3;
}

.zZindex {
  z-index: 999000 !important;
}
.custom-save-btn-investor-form{
  text-align: center;margin-top: 10px;
}
/deep/.dialogCustomClass{
  margin-top: 15% !important;
}
</style>
